﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace XNADevelopmentTutorialGame
{
    class Sprite
    {
        public string assetName;
        public Vector2 position = new Vector2(0, 0);
        private Texture2D mSpriteTexture;
        public Rectangle size;
        private float mScale = 1.0f;
        private Rectangle mSource;

        public Rectangle Source
        {
            get { return mSource; }
            set
            {
                mSource = value;
                size = new Rectangle(0, 0, (int)(mSource.Width * scale), (int)(mSource.Height * scale));
            }
        }

        public float scale
        {
            get { return mScale; }
            set
            {
                mScale = value;
                size = new Rectangle(0, 0, (int)(Source.Width * scale), (int)(Source.Height * scale));
            }
        }        

        public void LoadContent(ContentManager theContentManager, string theAssetName)
        {
            mSpriteTexture = theContentManager.Load<Texture2D>(theAssetName);
            assetName = theAssetName;
            Source = new Rectangle(0, 0, mSpriteTexture.Width, mSpriteTexture.Height);
            size = new Rectangle(0, 0, (int)(mSpriteTexture.Width * scale), (int)(mSpriteTexture.Height * scale));
        }

        public virtual void Draw(SpriteBatch theSpriteBatch)
        {
            theSpriteBatch.Draw(mSpriteTexture, position, Source,
            Color.Red,0.0f,Vector2.Zero,scale,SpriteEffects.None,0);
        }

        public void Update(GameTime gameTime, Vector2 theSpeed, Vector2 theDirection)
        {
            position += theDirection * theSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
        }

    }
}
